<?php
$page_title = "Adauga citate - Fifaonline.ro";
include_once ("top.php");
?>
<center><p class="text1">Quotes</p>
<?php
if (!isset($_SESSION['identitate']))
{
	header("Location: http://localhost");
	exit();
}
?>
<center>
<?php
	//Verifica daca formularu a fost transmis.
	if(isset($_POST['submitted']))
	{
		$errors = array(); //Initializeaza tabloul de erori.
	
		//Verifica titlul.
		if (empty($_POST["quote"]))
		{
			$errors[] = 'Ai uitat sa scrii citatul.';
		}
		else
		{
			$quote = trim($_POST["quote"]);
		}
	
		//Verifica continutul.
		if(empty($_POST["author"]))
		{
			echo 'Autorul setat ca anonim.';
			$author = 'Anonim';
		}
		else
		{
			$author = trim($_POST["author"]);
		}
		
		
		if(empty($errors)) //Daca totul e in regula
		{
			//Posteaza stirea pe homepage
			require_once ("/includes/mysql_connect.php"); //Se conecteaza la baza de date.
			
			//Creeaza interogarea
			$query = "INSERT INTO quotes (quote, author) VALUES ('$quote', '$author')";
			$result = @mysql_query($query); //Executa interogarea.
			if ($result) //Daca interogarea a fost realizata cu succes.
			{
				//Afiseaza un mesaj
				echo "<h1>Citat adaugat!</h1>";
				echo "<p>Citatul a fost adaugat.</p>";
			}
			else //Daca nu a mers bine.
			{
				echo "<h1>System Error!</h1>";
				echo "<p>A aparut o eroare de sistem:" . mysql_error() . "<br>Query: " . $query . "<p>";
				exit();
			}
			mysql_close(); //Inchide conexiunea cu baza de date.
		}
		else //Raporteaza erorile
		{
			echo "<h1>Erori</h1>
			<p>Au aparut urmatoarele erori:<br>";
			foreach ($errors as $msg) //Afiseaza fiecare erorare
			{
				echo "-$msg<br>\n";
			}
			echo "<br>Please try again!";
		}//Sfarsitul blocului IF(empty($errors)).
	}//Sfarsitul conditionalei principale.

?>
<form method="post" action="quotes.php" enctype="multipart/form-data">
<table>
<tr>
<td><p class="text1">Citat: </p></td>
<td> <textarea name="quote" value=""/></textarea></td>
</tr>
<tr>
<td><br /><p class="text1">Autor: </p></td>
<td> <input type="text" name="author" value=""/></td>
</tr>
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
</table>
<input type="submit" name="submitted" value="post" />
<input type="hidden" name="submitted" value="TRUE" />
</form>
<a href="logout.php">Logout</a><br>
<a href="manage.php">Manage</a><br>
<a href="poll_create.php">Polls</a>
</center>
<?php
include_once("end.php");
?>